<template>
	<view class="page">
		<u-navbar title-color="#fff" title=" " :background="background" :border-bottom="false" :is-back="false">

		</u-navbar>
		<view class="page-content ">
			<u-tabs :list="tabList" active-color="#70B52C" :is-scroll="true" :current="current"
				@change="change"></u-tabs>
			<view class="">
				<view style="background: #F4F4F4;position: relative;" @click="toInfo(item)" class="mb10" v-for="(item,index) in dataList" :key="index">
					
					<view v-if="item.file" class="ic-video">
					<u-icon name="play-circle"></u-icon>
						
					</view>
					<view v-if="item.poster">
						<image :src="item.poster" style="width: 100%;" mode="widthFix"></image>
					</view>
					<view v-else>
						<view class="u-flex u-f-jsb p15">
							<span style="max-width: 80px;width: 80px;text-align:center;border-bottom: 1px solid #000;" class="c0 fz14 u-font-bold pb2">
							
							{{item.shortName}}
							</span>
							<image :src="item.picUrl" style="height:300rpx;" mode="heightFix"></image>
							<span class="u-flex fz12 c6" style="min-width: 80px;max-width:80px">
								查看更多
								<u-icon name="arrow-right"></u-icon>
							</span>
						</view>
					</view>
				</view>

				<view class="">

					<u-loadmore :status="loadStatus" v-if="dataList.length>0" />
				</view>
				<view class="order-none u-flex u-f-justify fz16 c9 p50" v-if="dataList.length<=0">
					暂无数据！
				</view>
			</view>
		</view>



		<u-tabbar active-color="#70B52C" @change="tabbarChange" v-model="curTab" :list="tabbarList"
			:mid-button="true"></u-tabbar>
	</view>
</template>

<script>
	import {
		getPlatform
	} from '@/config/util.js'
	export default {
		data() {
			return {
				background: {
					background: ''
				},
				tabList: [],
				curTab: 2,
				current: 0,
				loadStatus: 'more',
				scrollHeight: 300,
				dataList: [],
				page: 1,
			}
		},
		computed: {
			tabbarList() {
				return this.$store.state.tabbarList || '';
			},
		},
		onLoad() {
			
				this.$nextTick(() => {
			
					this.$api.categoryAll({
						parentId:13,
					}, res => {
						if (res.code == 200) {
							this.tabList = res.data
							this.tabList.unshift({
								name: '全部',
								id: 13
							})
							this.initData()
						}
					})
				})
			
		},
		onShow() {},
		// 页面下拉到底部触发
		onReachBottom() {
			if (this.loadStatus == 'more') {
				this.getData()
			}
		},
		methods: {
			toInfo(item) {
				uni.navigateTo({
					url: '/pages/product/info?id='+item.id
				})
			},
			change(e) {
				this.current = e
				this.initData()

			},
			initData() {
				this.page = 1
				this.dataList = []
				this.getData()

			},
			toEdit(id) {
				uni.navigateTo({
					url: '/pages/order/confirm?order_id=' + id
				})
			},
			getData() {
				this.$api.productSearch({
					pageNo: this.page,
					pageSize: 10,
					categoryId: this.tabList[this.current].id
				}, res => {
					if (res.code == 200) {
						let _list = res.data.list
						this.dataList = [...this.dataList, ..._list]
						// 判断所有数据是否请求完毕
						if (res.data.total > this.dataList.length) {
							this.page++
							this.loadStatus = 'more'
						} else {
							this.loadStatus = 'noMore'
						}
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	page {
		background: #f5f5f5;
	}

	.module-btn {
		.btn {
			background: rgba(137, 195, 255, 0.3);
			color: rgb(26, 109, 255);
			height: 54upx;
			display: flex;
			align-items: center;
			justify-content: center;
			flex: 1;
			font-size: 24rpx;
			padding: 0 30rpx;
			border-radius: 50rpx;
			text-align: center;
			margin-left: 20rpx;
		}
	}
	.ic-video{
		position: absolute;
		top:30rpx;
		right:30rpx;
		font-size:60rpx;
		z-index: 2;
	}
</style>